<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="<%=basePath%>js/initPage.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>随便打TCS系统</title>

<!-- Bootstrap -->
<link href="<%=basePath%>vendors/bootstrap/dist/css/bootstrap.min.css"
	rel="stylesheet">
<!-- Font Awesome -->
<link
	href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
	rel="stylesheet">
<!-- NProgress -->
<link href="<%=basePath%>vendors/nprogress/nprogress.css"
	rel="stylesheet">
<!-- iCheck -->
<link href="<%=basePath%>vendors/iCheck/skins/flat/green.css"
	rel="stylesheet">

<!-- bootstrap-progressbar -->
<link
	href="<%=basePath%>vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css"
	rel="stylesheet">
<!-- JQVMap -->
<link href="<%=basePath%>vendors/jqvmap/dist/jqvmap.min.css"
	rel="stylesheet" />
<!-- bootstrap-daterangepicker -->
<link
	href="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.css"
	rel="stylesheet">

<!-- Custom Theme Style -->
<link href="<%=basePath%>build/css/custom.min.css" rel="stylesheet">
<style>
		/*三角标*/
	.triangle:before{
        content: '';
        border-left: 15px solid #E6E9ED;
        border-top: 15px solid transparent;
        border-right: 15px solid transparent;
        border-bottom: 0;
        position: absolute;
        left: 20px;
        top: 0;
        margin-right: -15px;
        margin-top: -15px;
        }
    .triangle:after{
        content: '';
        border-left: 15px solid #fff;
        border-top: 15px solid transparent;
        border-right: 15px solid transparent;
        border-bottom: 0;
        position: absolute;
        left: 21px;
        top: 1px;
        margin-right: -14px;
        margin-top: -14px;
        }
	.import_rule{
		background: rgba(255, 255, 255,1);
		position: absolute;
		display: none;
		z-index: 99;
		top:30px;
		left:40px;
		width:400px;
		border: 1px solid #E6E9ED;
		border-radius: 5px;
		padding:20px 10px ;
	}
	.import_rule img{
		width:100%;
		height:auto;
	}
	.import_rule i{
			color:#ddd;
			position: absolute;
			right:5px;
			top:5px;
			font-size: 16px;
		}
</style>
</head>

<body class="nav-md"> 
	<div class="container body">
		<div class="main_container">
			<div class="col-md-3 left_col">
				<div class="left_col scroll-view">

					<div class="clearfix"></div>

					<br />

				</div>
			</div>

			<!-- page content -->
			<div class="right_col" role="main">
				<div class="">
					<div class="page-title">
						<div class="title_left"></div>

						<div class="x_content">
						  <select class="btn btn-default dropdown-toggle" id="status" style="text-align: center;">
								<option value="3" <c:if test="${status == 3}">selected</c:if>> 全部</option>
								<option value="1" <c:if test="${status == 1}">selected</c:if>>已上架</option>
								<option value="0" <c:if test="${status == 0}">selected</c:if>>未上架</option>
						  </select>
						  <select class="btn btn-default dropdown-toggle" id="firstclassify" style="text-align: center;"
						       onchange="secondCategory()">
								<option value="分类" <c:if test="${firstclassify == 一级分类}">
									selected</c:if>>分类</option>
								<c:forEach items="${tourCategory}" var="s" varStatus="z">
									<option value="${s.id}"
									<c:if test="${s.id == firstclassify}">
									selected</c:if>>${s.category}</option>
								</c:forEach>
						  </select>
						     商品名: <input type="text" name="goodstext" id="goodstext"
								value="${goodstext}" />
							<button type="submit" class="btn btn-default"
								onclick="selectOEM(1)">搜索</button>
							<button type="submit" class="btn btn-success"
								onclick="addGoods()">添加</button>
						</div>
					</div>

					<div class="x_panel">

						<div class="x_content">

							<table id="datatable" class="table table-striped table-bordered">
								<thead>
									<tr>
										<th>序号</th>
										<th>商品名</th>
										<th>图片</th>
										<th>分类</th>
										<th>价格</th>
										<th>是否上架</th>
										<th>操作</th>
									</tr>
								</thead>

								<tbody>
									<c:forEach items="${tourGoods}" var="s" varStatus="z">
										<tr>
											<td>${s.numid}</td>
											<td>${s.goodstext}</td>
											<td><img style="width: 100px;height: 100px; display: block;" src="${s.showpic}" alt="image" /></td>
											<td>${s.firstclassify}</td>
											<td>${s.price}</td>
											<td><c:if test="${s.isgoods == 1}">已设为推荐</c:if>
											    <c:if test="${s.isgoods == 0}">未设为推荐</c:if></td>
											<td>
											   <c:if test="${s.isgoods == 0}">
											   <button type="button" class="btn btn-fail"
														onclick="openStatus('${s.id}')">设为推荐</button></c:if>
											    <c:if test="${s.isgoods == 1}">
											    <button type="button" class="btn btn-success"
														onclick="closeStatus('${s.id}')">取消推荐</button></c:if>
											    <button type="submit" class="btn btn-primary"
														onclick="updateGoods('${s.id}')">修改</button>
												<button type="submit" class="btn btn-default"
														onclick="updateDatastatus('${s.id}')">删除</button>
												<c:if test="${s.isgoods == 2}">
												<button type="submit" class="btn btn-default"
														onclick="index_SelfShopCoupon('${s.id}')">查看优惠券</button></c:if>
												</td>
										</tr>
									</c:forEach>
								</tbody>
							</table>
						</div>
					</div>
					<div class="clearfix"></div>
					<br />
				</div>
				<div style="width: 100%; text-align: center;">
					<div id='page'></div>
				</div>
			</div>
			<!-- /page content -->


			<script>
				/**
				 * 纯粹的JS分页插件，代码缺点：JS操作DOM冗余太多，太繁琐
				 */
				pageUtil.initPage('page', {
					totalCount : ${totlenum}, //总页数，一般从回调函数中获取。如果没有数据则默认为1页
					curPage : ${curPage}, //初始化时的默认选中页，默认第一页。如果所填范围溢出或者非数字或者数字字符串，则默认第一页
					showCount : 9, //分页栏显示的数量
					pageSizeList : [ 10 ], //自定义分页数，默认[5,10,15,20,50]
					defaultPageSize : 10, //默认选中的分页数,默认选中第一个。如果未匹配到数组或者默认数组中，则也为第一个
					isJump : true, //是否包含跳转功能，默认false
					isPageNum : true, //是否显示分页下拉选择，默认false
					isPN : true, //是否显示上一页和下一面，默认true
					isFL : true, //是否显示首页和末页，默认true
					jump : function(curPage, pageSize) { //跳转功能回调，传递回来2个参数，当前页和每页大小。如果没有设置分页下拉，则第二个参数永远为0。这里的this被指定为一个空对象，如果回调中需用到this请自行使用bind方法
						selectOEM(curPage);
					},
				});
			</script>

		</div>
	</div>
	<style>
.black_overlay {
	display: none;
	position: absolute;
	top: 0%;
	left: 0%;
	width: 100%;
	height: 100%;
	background-color: black;
	z-index: 1001;
	-moz-opacity: 0.8;
	opacity: .80;
	filter: alpha(opacity = 80);
}

.white_content {
	display: none;
	position: absolute;
	top: 20%;
	left: 30%;
	width: 60%;
	height: 60%;
	border: 16px solid white;
	background-color: white;
	z-index: 1002;
	overflow: auto;
	left: 30%;
}

.white_content_small {
	display: none;
	position: absolute;
	top: 40%;
	left: 40%;
	width: 40%;
	height: 40%;
	border: 16px solid white;
	background-color: white;
	z-index: 1002;
	overflow: auto;
}
</style>
    <script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
    <script src="<%=basePath%>static/js/postbird-img-glass.min.js"></script>
    <script>
		PostbirdImgGlass.init({
			domSelector: "img",
			animation: true
		});
	</script>
    <script>
		$('.RuleWatch').click(function () {
			if ($('.import_rule').css("display") == "none") {
				$('.import_rule').fadeIn(200);
			}
		});
		//二级菜单关闭按钮
		$(".import_rule>i").on("click", function () {
			console.log("关闭");
			$('.import_rule').fadeOut(200);
		})
	</script>
    <script type="text/javascript">
	$('#upload').click(function() {
		var file = document.myForm.file.files[0];

		if (file != null || file != undefined) {

			var fileName = file.name.substring(file.name.lastIndexOf(".")+1).toLowerCase();
			
			if(fileName !="xls" && fileName !="xlsx"){
				alert("只能上传.xls  .xlsx类型的文件!");
	            return;
			}
			
			var fm = new FormData();

			fm.append('file', file);

			$.ajax(
				{
					url : "<%=basePath%>apiTest/uploadExcel",
					type : 'POST',
					data : fm,
					contentType : false, //禁止设置请求类型
					processData : false, //禁止jquery对DAta数据的处理,默认会处理
					//禁止的原因是,FormData已经帮我们做了处理
					success : function(result) {
						//测试是否成功
						//但需要你后端有返回值
						daoru(result.json);
					}
				}
			);
		} else {
		}
	});	
	</script>
	<script type="text/javascript">
		function selectOEM(curPage) {
			var goodstext = $("#goodstext").val();
			var status = $("#status").find("option:selected").val();
			var firstclassify = $("#firstclassify").find("option:selected").val();
			var secondclassify = $("#secondclassify").find("option:selected").val();
			location.href = "selectTourGoods?curPage=" + curPage +
			        "&goodstext=" + goodstext +
			        "&status=" + status +
			        "&firstclassify=" + firstclassify +
			        "&secondclassify=" + secondclassify;
		}
		
		//弹出隐藏层
		function ShowDiv(show_div, bg_div) {
			document.getElementById(show_div).style.display = 'block';
			document.getElementById(bg_div).style.display = 'block' ;
			var bgdiv = document.getElementById(bg_div);
			bgdiv.style.width = document.body.scrollWidth;
			// bgdiv.style.height = $(document).height();
			$("#" + bg_div).height($(document).height());
		}
        //关闭弹出层
		function CloseDiv(show_div, bg_div) {
			document.getElementById(show_div).style.display = 'none';
			document.getElementById(bg_div).style.display = 'none';
		}
        function addGoods() {
			location.href = "add_TourGoods";
		}
		function updateGoods(id) {
			location.href = "update_TourGoods?id=" + id;
		}
		
		// ajax 对象
		function ajaxObject() {
			var xmlHttp;
			try {
				// Firefox, Opera 8.0+, Safari
				xmlHttp = new XMLHttpRequest();
			} catch (e) {
				// Internet Explorer
				try {
					xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					try {
						xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e) {
						alert("您的浏览器不支持AJAX！");
						return false;
					}
				}
			}
			return xmlHttp;
		}
	
		function updateDatastatus(id) {
			var ajax = ajaxObject();
			ajax.open("post", "updateTourGoods?id=" + id +
				"&datastatus=" + 0, false);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.onreadystatechange = function() {
				if (ajax.readyState == 4) {
					if (ajax.status == 200) {
						var result = ajax.responseText;
						if (result == "success") {
							//请求成功
							alert("项目已删除");
							location.href = "tourGoods";
						} else {
							//请求成功
							alert(result);
						}
					} else {
						//请求失败
						alert("请求终止，请检查操作或联系客服咨询" + ajax.status);
	
					}
				} else {
	
				}
			};
			ajax.send();
		}
		
		function openStatus(id) {
			var ajax = ajaxObject();
			ajax.open("post", "updateTourGoods?id=" + id +
				"&isgoods=" + 1, false);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.onreadystatechange = function() {
				if (ajax.readyState == 4) {
					if (ajax.status == 200) {
						var result = ajax.responseText;
						if (result == "success") {
							//请求成功
							alert("已设为推荐");
							location.href = "tourGoods";
						} else {
							//请求成功
							alert(result);
						}
					} else {
						//请求失败
						alert("请求终止，请检查操作或联系客服咨询" + ajax.status);
	
					}
				} else {
	
				}
			};
			ajax.send();
		}
		
		function closeStatus(id) {
			var ajax = ajaxObject();
			ajax.open("post", "updateTourGoods?id=" + id +
				"&isgoods=" + 0, false);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.onreadystatechange = function() {
				if (ajax.readyState == 4) {
					if (ajax.status == 200) {
						var result = ajax.responseText;
						if (result == "success") {
							//请求成功
							alert("已取消推荐");
							location.href = "tourGoods";
						} else {
							//请求成功
							alert(result);
						}
					} else {
						//请求失败
						alert("请求终止，请检查操作或联系客服咨询" + ajax.status);
	
					}
				} else {
	
				}
			};
			ajax.send();
		}
		
		function secondCategory(){
			var firstclassify = $("#firstclassify").find("option:selected").val();
			
			if(firstclassify == "一级分类"){
				 var secondclassify = "二级分类";
				 var str = '<option value='+secondclassify+'>请先选择二级分类</option>';
				 $("#secondclassify").html(str);
			}else{
				$.ajax({
		            url : "nextCategory", 
		            type : 'POST',
		            dataType: 'json',  
		            async : false,
		            data : {
		            	"topid" : firstclassify
		            },
		            success : function(data) { 
		            	var str;
		            	$.each(data, function(i, item) {
		                    var category= item.category;
		                    var id= item.id;
		                    var secondclassify = "${secondclassify}";
		                    str += '<option value='+secondclassify+'>二级分类</option>';
		                    str += '<option value='+id+'>'+category+'</option>';
	                        $("#secondclassify").html(str);
		                })
		            }
		        });
			}
		}
	</script>
	<!-- jQuery -->
	<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
	<!-- Bootstrap -->
	<script src="<%=basePath%>vendors/bootstrap/dist/js/bootstrap.min.js"></script>
	<!-- FastClick -->
	<script src="<%=basePath%>vendors/fastclick/lib/fastclick.js"></script>
	<!-- NProgress -->
	<script src="<%=basePath%>vendors/nprogress/nprogress.js"></script>
	<!-- bootstrap-daterangepicker -->
	<script src="<%=basePath%>vendors/moment/min/moment.min.js"></script>
	<script
		src="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.js"></script>
	<!-- Chart.js -->
	<script src="<%=basePath%>vendors/Chart.js/dist/Chart.min.js"></script>
	<!-- Custom Theme Scripts -->
	<script src="<%=basePath%>build/js/custom.min.js"></script>
	<!-- layui -->
	<script src="<%=basePath%>vendors/layui/layui.js"></script>

</body>
</html>